package xdu.ble.alarm.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xdu.ble.alarm.entity.Alarm;
import xdu.ble.alarm.service.AlarmService;


/**
 * @Author com.alibaba.lizhen
 * @Date 2021/1/30 1:08 下午
 * @Version 1.0
 * @Description
 */
@RestController
@RequestMapping("/alarm")
public class AlarmController {

    private final Logger logger = LoggerFactory.getLogger(AlarmController.class);

    @Autowired
    private AlarmService alarmService;

    @RequestMapping(value = "/active")
    public boolean register(@RequestBody Alarm alarm) {
        return alarmService.activeAlarm(alarm);
    }

    /**
     * 根据报警器id查询报警器信息
     *
     * @return Result
     */
    @RequestMapping(value = "/find")
    public Alarm findAlarmByAlarmId(String alarmId) {
        System.out.println("alarm Controller invoke， alramId = " + alarmId);
        return alarmService.findAlarmById(alarmId);
    }

    /**
     * 根据nbDeviceId查询报警器信息
     *
     * @return Result
     */
    @RequestMapping(value = "/findByDeviceId")
    public Alarm findAlarmByNbDeviceId(String nbDeviceId) {
        return alarmService.findAlarmByNBDeviceId(nbDeviceId);
    }

    /**
     * 根据报警设备id查看信息
     *
     * @return Result
     */
    @RequestMapping(value = "/update")
    public boolean updateAlarmInfo(@RequestBody Alarm alarm) {
        logger.debug("patient = " + alarm);
        return alarmService.updatePatientInfo(alarm);
    }


    /**
     * 解除警报
     *
     * @return Result
     */
    @RequestMapping(value = "/release")
    public boolean releaseAlarm(String alarmId) {
        return alarmService.releaseAlarm(alarmId);
    }
}
